<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
	<head>
		<jsp:include page="../inc.jsp"></jsp:include>
		<meta http-equiv="X-UA-Compatible" content="edge" />
		<link rel="stylesheet" type="text/css" href="${ctx}/style/notice/notice.css" />
		
		<c:if test="${fn:contains(sessionInfo.resourceList, '/role/edit')}">
			<script type="text/javascript">
		$.canEdit = true;
	</script>
		</c:if>
		<c:if test="${fn:contains(sessionInfo.resourceList, '/role/delete')}">
			<script type="text/javascript">
		$.canDelete = true;
	</script>
		</c:if>
		<c:if test="${fn:contains(sessionInfo.resourceList, '/role/grant')}">
			<script type="text/javascript">
		$.canGrant = true;
	</script>
		</c:if>
		<title></title>
	<script type="text/javascript">
	var dataGrid;
	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			url : '${ctx}' + '/training/dataGrid',
			striped : true,
			rownumbers : true,
			pagination : true,
			singleSelect : true,
			idField : 'id',
			sortName : 'id',
			sortOrder : 'asc',
			pageSize : 50,
			pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
			frozenColumns : [ [ {
				width : '600',
				title : '培训条目',
				field : 'name',
				sortable : true,
				formatter : function(value, row, index) {
					var str = '&nbsp;';
					str += $.formatString('<a href="javascript:void(0)" onclick="grantFun(\'{0}\');" >' + value +'</a>', row.id);
					return str;
				}
			} , {
				title : '日期',
				field : 'description'
			}  ] ],
			toolbar : '#toolbar'
		});
	});
	
	function addFun() {
		parent.$.modalDialog({
			title : '添加',
			width : 500,
			height : 300,
			href : '${ctx}/role/addPage',
			buttons : [ {
				text : '添加',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#roleAddForm');
					f.submit();
				}
			} ]
		});
	}
	
	function deleteFun(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].id;
		} else {//点击操作里面的删除图标会触发这个
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.messager.confirm('询问', '您是否要删除当前用户？', function(b) {
			if (b) {
				var currentUserId = '${sessionInfo.id}';/*当前登录用户的ID*/
				if (currentUserId != id) {
					progressLoad();
					$.post('${ctx}/role/delete', {
						id : id
					}, function(result) {
						if (result.success) {
							parent.$.messager.alert('提示', result.msg, 'info');
							dataGrid.datagrid('reload');
						}
						progressClose();
					}, 'JSON');
				} else {
					parent.$.messager.show({
						title : '提示',
						msg : '不可以删除自己！'
					});
				}
			}
		});
	}
	
	function editFun(id) {
		if (id == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].id;
		} else {
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.modalDialog({
			title : '编辑',
			width : 500,
			height : 300,
			href : '${ctx}/role/editPage?id=' + id,
			buttons : [ {
				text : '编辑',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#roleEditForm');
					f.submit();
				}
			} ]
		});
	}
	
	function grantFun(id) {
		parent.$.modalDialog({
			title : 'CMS training!',
			width : 500,
			height : 500,
			href : '${ctx}/training/trainContent?id=' + id,
		});
	}
	
	</script>
	</head>
	<body class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'center',fit:true,border:false">
			<table id="dataGrid" data-options="fit:true,border:false"></table>
		</div>
		<div id="toolbar" style="display: none;">
			<c:if test="${fn:contains(sessionInfo.resourceList, '/role/add')}">
				<h3 class="training-title">培训通知</h3>
			</c:if>
		</div>
	</body>
</html>